import 'package:cloud_medicine/components/util.dart';
import 'package:cloud_medicine/model/base_user_info.dart';
import 'package:cloud_medicine/pages/other_user_show.dart';
import 'package:flutter/material.dart';

// 用户头像
class UserAvatar extends StatelessWidget {
  final double imageStyle; // 用户头像avatar样式
  final String avatar; // 头像路径
  final int userID; // 用户ID

  UserAvatar({
    Key key,
    this.imageStyle = 80,
    @required this.avatar,
    this.userID,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        if(user == null) {
          errorToast('处于未登陆状态，不允许查看信息，请登陆重试');
          return;
        }
        if (userID != null) {
          Navigator.of(context).push(MaterialPageRoute(
            builder: (context) => OtherUserShowPage(
              userID: userID,
            ),
          ));
        }
      },
      child: Container(
        width: imageStyle,
        height: imageStyle,
        child: ClipRRect(
          borderRadius: BorderRadius.circular(imageStyle / 2),
          child: FadeInImage.assetNetwork(
            placeholder: 'images/loading.gif', // 占位图
            image: avatar,
          ),
        ),
      ),
    );
  }
}
